<template>
  <uni-file-picker
      v-model="files"
      fileMediatype="image"
      mode="grid"
      @select="select"
      @progress="progress"
      @success="success"
      @fail="fail"
      @delete="deleteFile"
      :title="title"
  />
</template>

<script>
import {BASE_URL} from "../../../api/service";

export default {
  name: "FileUpload",
  props: ["associateFormId", "associateFormName","title","operateType"],
  data() {
    return {
      // imageValue: [],
      files: [],
    }
  },
  created(){
    if(this.operateType === "view"){
      this.init();
    }
  },
  methods: {
    // 获取上传状态
    select(e) {
      console.log('选择文件：', e)
      e.tempFiles.forEach(file=>{
        this.files.push(file)
      })
      this.$emit("change",this.files)
      console.log(this.files)

    },
    // 获取上传进度
    progress(e) {
      console.log('上传进度：', e)
    },

    // 上传成功
    success(e) {
      console.log('上传成功')
    },

    // 上传失败
    fail(e) {
      console.log('上传失败：', e)
    },
    deleteFile(e){
      var index0 = this.files.findIndex(item => {
        if (item.uuid == e.tempFile.uuid) {
          return true
        }
      })
      this.files.splice(index0, 1)
      this.$emit("change",this.files)
    }
  }

}
</script>

<style scoped>

</style>